package com.universityJob.modules.app.controller;

import com.universityJob.common.exception.RRException;
import com.universityJob.modules.app.utils.WXPublicUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mao on 2021/5/17.
 * @version 1.0 maozhijob@163.com
 */
@RestController
@RequestMapping("/app")
@Api("验证公众平台token")
@Slf4j
public class WXTokenController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private WXPublicUtils wxPublicUtils;

    @RequestMapping("/wxpublic/verify_wx_token")
    public String verifyWXToken(HttpServletRequest request) throws RRException {
        String msgSignature = request.getParameter("signature");
        String msgTimestamp = request.getParameter("timestamp");
        String msgNonce = request.getParameter("nonce");
        String echostr = request.getParameter("echostr");
        logger.info(" signature {}, timestamp {}, nonce {}, echostr {}",msgSignature,msgTimestamp,msgNonce
        ,echostr);
        if (wxPublicUtils.verifyUrl(msgSignature, msgTimestamp, msgNonce)) {
            return echostr;
        }
        return null;
    }

}
